﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Idlesoft.Utils
{
	public static class SameExtensions
	{
		#region same
		public static bool Same<TItem>(this TItem lhs, TItem rhs)
		{
			bool equals = true;
			if (lhs != null && rhs != null)
				equals = lhs.Equals(rhs);
			else if (lhs == null && rhs == null) { }
			else
				equals = false;
			return equals;
		}
		public static bool SequenceSame<TItem>(this IEnumerable<TItem> lhs, IEnumerable<TItem> rhs)
		{
			bool equals = true;
			if (lhs != null && rhs != null && lhs.Count() == rhs.Count())
				equals = lhs.SequenceEqual(rhs);
			else if (lhs == null && rhs == null) { }
			else
				equals = false;

			return equals;
		}
		public static bool AnySame<TItem>(this TItem item, IEnumerable<TItem> items)
		{
			return items.Any(i => i.Same(item));
		}
		public static bool AllSame<TItem>(this TItem item, IEnumerable<TItem> items)
		{
			return items.All(i => i.Same(item));
		}
		#endregion same
	}
}
